<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="测站名称" prop="stCd">
        <el-select v-model="queryParams.stCd" clearable filterable placeholder="请选择测站">
          <el-option v-for="item in allStationList" :key="item.stCd" :label="item.stName" :value="item.stCd">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="统计时间" prop="statisticTime">
        <el-date-picker v-model="queryParams.statisticTime" type="date" placeholder="选择日期"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="false"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getPage"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="page" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="测站编码" prop="stCd" width="200"/>
      <el-table-column label="测站名称" prop="stInfoConfigEntity.stName"/>
      <el-table-column label="统计时间" prop="statisticTime" width="200"/>
      <el-table-column label="应上报数据条数(条)" prop="shouldAmount" width="200"/>
      <el-table-column label="实际上报数据条数(条)" prop="actualAmount" width="200"/>
      <el-table-column label="数据上报率(%)" prop="reportRate" width="200"/>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getPage"
    />
  </div>
</template>

<script>
  import {
    page
  } from "@/api/dataquery/reportstatistics";
  import {
    getAllStation
  } from "@/api/analysisconfigure/stationaccess";

  export default {
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        page: null,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        dialogType: '',
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          stCd: '',
          analysisGroupId: ''
        },
        allStationList: []
      };
    },
    created() {
      this.getPage();
      this.getAllStation();
    },
    methods: {
      /** 查询分页列表 */
      getPage() {
        this.loading = true;
        page(this.queryParams).then(response => {
            this.page = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getPage();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 查询所有接入测站列表 */
      getAllStation() {
        getAllStation().then(response => {
          this.allStationList = response.data;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/user/export', {
          ...this.queryParams
        }, `user_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
